import pandas as pd

from pyecharts import options as opts
from pyecharts.charts import Bar,Line,Scatter

'''1.加载数据'''
data = pd.read_excel('top10.xlsx')

salary = (
    Bar(
        #1.初始化配置项：InitOpts
        init_opts=opts.InitOpts(
            width="900px",
            height="600px",
            page_title='成都地区算法岗位工资排名Top10的公司',

        )
    )
    #2.要显示的数据
    .add_xaxis(data['company_name'].tolist())
    .add_yaxis("工资",data['salary'].tolist(),bar_width='50%')
    #3.全局配置项set_global_opts
    .set_global_opts(
        #3.1标题配置
        title_opts=opts.TitleOpts(
            title='成都地区算法岗位工资排名Top10的公司',
            title_textstyle_opts=opts.TextStyleOpts(color='Blue',font_family='Arial',font_size=20),
            pos_left='center',
            pos_top='0px',
            pos_bottom='20px',
            subtitle='叶玉婷 第一张数据分析图',
            subtitle_textstyle_opts=opts.TextStyleOpts(color="red",font_family='Arial',font_size=15),

        ),
        #3.2区域缩放配置项
        datazoom_opts=opts.DataZoomOpts(
            is_show=True,
            type_='slider',
            is_realtime=True,
            range_start=0,
            range_end=100,
            orient='horizontal',
            is_zoom_lock=False,
        ),
        #3.3图例配置项
        legend_opts=opts.LegendOpts(
            type_='plain',
            is_show=True,
            pos_right='10%',
            orient='vertical',
            selected_mode='multiple',
            align='left',
            padding=10,
            item_gap=5,
            item_width=30,
            item_height=15,
            inactive_color='#ccc',
            legend_icon='circle'
        ),
        #3.4视觉映射配置项目
        visualmap_opts=opts.VisualMapOpts(
            is_show=True,
            type_='color',
            min_=18000,
            max_=27500,
            range_opacity=0.9,
            range_color=['blue','green','red'],
            orient='vertical',
            pos_right='0%',
            pos_bottom='0%',
        ),
        #3.5坐标轴配置
        xaxis_opts=opts.AxisOpts(
            is_show=True,
            type_='category',
            axislabel_opts={"interval": "0"},
        ),
        yaxis_opts=opts.AxisOpts(
            axislabel_opts={"interval": "0"},
            axisline_opts=opts.AxisLineOpts(is_show=True),
            axistick_opts=opts.AxisTickOpts(is_show=True),
            is_show=True,
        )
    )
    #4.系列配置set_series_opts
    .set_series_opts(
        #4.1图元样式配置项ItemStyleOpts 柱形图外观设置
        itemstyle_opts=opts.ItemStyleOpts(
            color='black',
            opacity=1,
            border_color='green',
            border_width=1,
        ),
        #4.2线样式配置;LineStyleOpts:,柱形图边框设置
        linestyle_opts=opts.LineStyleOpts(
            is_show=True,
            width=1,
            color='red',
            type_='dotted',
        ),
        #4.3标签配置项
        label_opts=opts.LabelOpts(
            is_show=True,
            position='top',
            color='black',
            font_size=14,
            font_family='Arial',
            font_style='italic',
            font_weight='bold',
            rotate=0
        ),
        #4.4标记点配置：MarkPointOpts
        markpoint_opts=opts.MarkPointOpts(
            data=[
                #type_:特殊标记类型，min，max，average
                #symbol：形状roundRect，pin
                #symbol_size：标记点的大小
                opts.MarkPointItem(type_='max',symbol='pin',symbol_size=100,
                                   itemstyle_opts=opts.TextStyleOpts(color="red")),
                opts.MarkPointItem(type_='min',
                                   symbol='pin',
                                   symbol_size=100,
                                   itemstyle_opts=opts.ItemStyleOpts(color="green")),
            ],
                label_opts=opts.LabelOpts(
                    color='white',
                    font_size=18
                ),
        ),
        #4.5标记线配置markline_opts
        markline_opts=opts.MarkLineOpts(
            data=[
                opts.MarkLineItem(type_='average',name='平均值',symbol_size=10),
            ],
            label_opts=opts.LabelOpts(
                color='blue',
                font_size=20
            ),
            linestyle_opts=opts.LineStyleOpts(width=3,color='blue')
        )
    )
)
salary.render('6.2(1) top10.html')